package com.yanqu.road.server.cmd.activity.newyear2023.redpacket;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.FireWorkProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.newyear2023.FireWorkModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_FIREWORK_RP_ROB_USER, desc = "抢红包的人的列表")
public class FireWorkRobUserCmd extends AbstractCommand {

    private int activityId;
    private int no;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        FireWorkProto.FireWorkRedPacketTableRobUserReqMsg reqMsg = FireWorkProto.FireWorkRedPacketTableRobUserReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        no = reqMsg.getNo();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        int resRet = player.getModule(FireWorkModule.class).checkCommon(activityId,2);
        if(resRet != 0){
            ret = resRet;
            return;
        }
        ret = player.getModule(FireWorkModule.class).tableRobUserList(activityId,no);

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            FireWorkProto.FireWorkRedPacketTableRobUserRespMsg.Builder respMsg = FireWorkProto.FireWorkRedPacketTableRobUserRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_FIREWORK_RP_ROB_USER, respMsg);
        }
    }
}
